package com.cg.slms.dao;

import java.util.ArrayList;
import java.util.List;

import org.mybatis.spring.SqlSessionTemplate;

import com.cg.slms.domain.Stockin;

//创建实现类并加入findStockin实现方法
public class StockinDao implements IStockinDao{
	private SqlSessionTemplate sqlSession;
	public List<Stockin> findStockin(Stockin stockin){
		List<Stockin> stockins=new ArrayList<Stockin>();
		stockins=sqlSession.selectList("findStockin", stockin);
		System.out.println("dao::"+stockin.getClient().getId()+"---"+stockin.getEmployee().getId()+"---"+stockin.getMerchandise().getId());
		return stockins;
	}
	public SqlSessionTemplate getSqlSession() {
		return sqlSession;
	}
	public void setSqlSession(SqlSessionTemplate sqlSession) {
		this.sqlSession = sqlSession;
	}
	
	public int addStockin(Stockin stockin) {
		int res = sqlSession.insert("addStockin",stockin);
		return res;
	}
	
	public Stockin findStockinById(String id) {
		Stockin stockin = sqlSession.selectOne("findStockinById",id);
		return stockin;
	}
	
	public boolean updateStockin(Stockin stockin) {
		System.out.println("修改数据："+stockin.getId()+"--");
		int ref = sqlSession.update("updateStockin", stockin);
		if(ref > 0) {
			return true;
		}else {
			return false;
		}
	}
	
	public boolean deleteStockinById(Stockin stockin) {
		int ref = sqlSession.delete("deleteStockinById",stockin);
		System.out.println("订货单id："+stockin.getId());
		if(ref>0) {
			return true;
		}else {
			return false;
	    }
	}
}
